<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","upp_sch_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.DelPro.SchName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("PID").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","pronames.php?q="+val,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function getProYear(com)
{
var xmlhttp;  
var sch=document.forms["DelPro"]["SchName"].value;
var hin=com+","+sch; 
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Pro_year").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_Pro_year.php?q="+hin,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function DeleteVerification()
{
   
  <?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}   
   else
   {
   ?>
   var P_Id=document.forms["DelPro"]["Pro_Name"].value;
var S_Id=document.forms["DelPro"]["SchName"].value;
var Year=document.forms["DelPro"]["Year"].value;
var Grade=document.forms["DelPro"]["Grade"].value;
 if(P_Id=="Select One"||S_Id==""||Year=="Select One"||Grade=="Select One")
	   {
		 alert("Please select the Programme name,School's name and Year!");
   return false;
	   }  
  if(P_Id!="Select One"&&S_Id!=""&&Year!="Select One"&&Grade!="Select One")
	   {	  
var r=confirm("Are you sure to delete this?");
if (r==true)
  {
     return true;

 }

if(r==false)
  {
 return false;
  }
}
}
</script>
</head>
<body>
 <?php
require_once '../Login/databaseconnection.php';
if(!loggedin())
{
require_once '../index.php';

}
   
   else
   {
   
  ?>
  
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttable">
<form  name="DelPro" action="#" method="POST" onSubmit="return DeleteVerification()">
<?php
if(isset($_POST['Delete']))
{
require_once 'DEL.php';
}
?>
  <table width="441" border="0" class="tablefontv">
    <tr>
      <td height="18" colspan="3"  scope="row" class="err">
      <?php
      if(isset($_POST['Delete']))
{
	if(isset($_SESSION['errorin']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
	if(isset($_SESSION['errornot']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot'];
		unset($_SESSION['errornot']);
	}
	if(isset($_SESSION['errornot2']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornot2'];
		unset($_SESSION['errornot2']);
	}
}   
?>
</td>
      </tr>
    <tr>
      <td width="164" height="29"  scope="row" bgcolor="#6AB5FF">School's Name:</td>
      <td width="142" bgcolor="#999999">
        <?php
	 	if($_SESSION['Access_Type']=="Teacher in Charge")
{
	$NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id']; 
    $snam=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
}
	 echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40' readonly='readonly'/>";
}
	else if($_SESSION['Access_Type']=="Administrator")
{
	if(!isset($SchName))
	{
		$snam=mysql_query("SELECT * FROM school WHERE School_Id='$School_Idc'");
	  if($ros=mysql_fetch_array($snam))
	  {
	  $SchName=$ros['Name'].','.$ros['Address'];
	  }
	}
	    echo "<input type='text' id='SchName' name='SchName' onKeyUp='showHint(this.value)' value='$SchName' size='40'/>";
}
	  ?></td>
      <td width="103" rowspan="3" bgcolor="#6AB5FF">&nbsp;</td>
    </tr>
    <tr>
      <td height="30" scope="row" bgcolor="#6AB5FF">Programme Name:</td>
      <td bgcolor="#999999"><div id="PID"><select name="Pro_Name" id="Pro_Name" onChange="getProYear(this.value)"">
        <?php
	   	 if($P_Id!="")
	  {
	    $resultnet=mysql_query("SELECT * FROM programme WHERE Programme_Id='$P_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$P_Name=$rownet['Programme_Name'];
}
	echo '<option value="'.$P_Name.'">'.$P_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
		if($Sch_Id!="")
		{
			$pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes WHERE School_Id='$Sch_Id'");
		}
		if($Sch_Id=="")
		{
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
		}
	  
  while($row=mysql_fetch_array($pro))
  {
  $p_id=$row['Programme_Id'];
	 $resultnet=mysql_query("SELECT * FROM programme WHERE Programme_Id='$p_id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$p_Name=$rownet['Programme_Name'];
}
if($p_Name!=$P_Name)
{
	  echo '<option value="'.$p_Name.'">'.$p_Name.'</option>';
	  }
  }
 
	  ?>
      </select></div></td>
            </tr>
    <tr>
      <td height="23" scope="row" bgcolor="#6AB5FF">Year:</td>
      <td bgcolor="#999999">
      <div id="Pro_year"><select name="Year" id="select">
        <?php
	  
	  if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Year.'">'.$Year.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $pro=mysql_query("SELECT DISTINCT(Year) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	 $yea=$row['Year'];
if($year!=$yea)
{
	  echo '<option value="'.$yea.'">'.$yea.'</option>';
	  }
  }
	 ?>
      </select></div></td>
      </tr>
	   <tr>
      <td height="23" scope="row" bgcolor="#6AB5FF">Grade:</td>
      <td bgcolor="#999999">
      <div id="Pro_grade"><select name="Grade" id="select">
        <?php
	  
	  if(isset($_POST['Delete']))
	  {
	 echo '<option value="'.$Grade.'">'.$Grade.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $pro=mysql_query("SELECT DISTINCT(Grade) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	 $Gra=$row['Grade'];
if($Grade!=$Gra)
{
	  echo '<option value="'.$Gra.'">'.$Gra.'</option>';
	  }
  }
	 ?>
      </select></div></td>
      </tr>
  </table>

  <br/>
      <a href="DelPro.php" class="reset">Reset |</a>
    <input name="Delete" align="middle" type="submit" value="Delete" class="buttonok"/>
    <br/>
   </form>
    <?php
    
   	   if(isset($_POST['Delete']))
{
	if($_SESSION['Access_Type']=="Administrator"||$_SESSION['Access_Type']=="Teacher in Charge")
   {  
   if($P_Id!=""&&$S_Id!=""&&$Year!=""&&$no_m_stu!=""&&$no_f_stu!=""&&$Grade!="")
   {
    echo '<table width="458" border="0" class="tablefontv">';

    ?>
    <?php
       echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Programme Name:";
		echo '</th>';
        echo '<td width="144">';
		echo $p_name;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of male students:";
		echo '</th>';
        echo '<td>';
		echo $no_m_stu;
		echo '</td>';
      echo '</tr>';
	     echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of female students:";
		echo '</th>';
        echo '<td>';
		echo $no_f_stu;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of teachers in training:";
		echo '</th>';
        echo '<td>';
		echo $te_in_trai;
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Number of trained teachers :";
		echo '</th>';
       echo '<td>';
	   echo $tra_tea;
	   echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Availability of books:"; 
		echo '</th>';
        echo '<td>';
		echo $Ava_books;
            
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Availability of teachers guides:"; 
		echo '</th>';
        echo '<td>';
		echo $Ava_T_Gui;
		echo '</td>';
      echo '</tr>';
     echo '</table>';
	 }
	}
	}	
	}
	  ?>
	   </div>
  <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div></div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">PROGRAMMES</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
	 }
  
?>
</body>
</html>